<?php

namespace app\admin\controller;

use think\Controller;
use think\facade\Request;
use think\facade\View;
use think\facade\Json;
use app\common\model\Order;
class Content extends Base
{
     //全局查询条件
   public function index()
   {

       $where   = [
           'bussiness_type' => 1
       ];
       $keyword = Request::param('keyword');
       if (!empty($keyword)) {
           $where[] = ['name', 'like', '%' . $keyword . '%'];
       }
       $dateran = Request::param('dateran');
       if (!empty($dateran)) {
        $getDateran = get_dateran($dateran);
        $where[]    = ['create_time', 'between', $getDateran];
       }
       $list = Order::getList($where, $this->pageSize, ['id' => 'desc']);
       $all_orderNum = model('order')->where('bussiness_type',1)->select();
       $view = [
           'keyword'  => $keyword,
           'dateran'  => $dateran,
           'pageSize' => page_size($this->pageSize, $list->total()),
           'page'     => $list->render(),
           'list'     => $list,
           'empty'    => empty_list(9),
           'all_order_num' => $all_orderNum
       ];
       View::assign($view);
       return view();
   }
   //删除
   public function del()
   {
       $id = Request::param('id');
       Order::destroy($id);
       return json(['error' => 0, 'msg' => '删除成功']);
   }

   //批量删除
   public function selectDel()
   {
       $id = Request::param('id');
       Order::destroy($id);
       return json(['error' => 0, 'msg' => '删除成功!']);
   }
   
   //失联亲人详情
   public function details($id){
       $order = model('order')::with('province1,city1')->where('id',$id)->find();
       $viewData = [
           'order' => $order
       ];
       $this->assign($viewData);
       return view();
   }

   //修改
    public function edit(){
        if(request()->isAjax()){
            $data = input('post.');
            $order = Order::get($data['id']);
            $order->title = $data['title'];
            $order->describe = $data['describe'];
            $order->status = 1;
            $res = $order->save();
            if($res){
                $this->success('成功!',$_SERVER['HTTP_REFERER']);
            }else{
                $this->error('失败！',$_SERVER['HTTP_REFERER']);
            }
        }
    }
}
